using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CheckVersion : MonoBehaviour
{
	public static CheckVersion instance;

	public static bool shown;

	public static bool isChecked;

	public static bool actualVersion = true;

	public bool forceShow;

	public List<GameObject> enabledGameObject = new List<GameObject>();

	public List<GameObject> disabledGameObject = new List<GameObject>();

	private void Awake()
	{
		instance = this;
	}

	private void OnDestroy()
	{
		instance = null;
	}

	private void OnEnable()
	{
		if (!isChecked)
		{
			StartCoroutine(CheckWithDelay());
		}
		else if (!actualVersion)
		{
			ShowUpdate();
		}
	}

	private IEnumerator CheckWithDelay()
	{
		yield return new WaitForSeconds(1f);
		ParseJSON(JSONManager.Instance.GetJSON(URLs.CheckVersion));
	}

	private void ParseJSON(string text)
	{
		if (!isChecked && !text.Equals(string.Empty))
		{
			isChecked = true;
			string text2 = BuildNumberForInapps.BuildNumber.Replace(".", string.Empty);
			while (text2.Length < text.Length)
			{
				text2 += "0";
			}
			if (Convert.ToInt32(text2) < Convert.ToInt32(text))
			{
				actualVersion = false;
				ShowUpdate();
			}
		}
	}

	public void ShowUpdate()
	{
		foreach (GameObject item in enabledGameObject)
		{
			item.SetActive(true);
		}
		foreach (GameObject item2 in disabledGameObject)
		{
			item2.SetActive(false);
		}
	}

	public void CloseMessage()
	{
		enabledGameObject.ForEach(delegate(GameObject g)
		{
			g.SetActive(false);
		});
	}

	public void GetNewVersion()
	{
		Application.OpenURL("https://play.google.com/store/apps/details?id=block.app.wars");
	}
}
